﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.ubosi.common;

namespace com.ubosi.spider.config
{
    /// <summary>
    /// Spider抓取配置
    /// </summary>
    public class SpiderConfig
    {        
        public static SpiderConfig GetSpiderConfig()
        {
            return (SpiderConfig)SerializerUtility.DeSerializeFromFile(typeof(SpiderConfig), Environment.CurrentDirectory + "\\Config\\SpiderConfig.xml");
        }

        /// <summary>
        /// 酒店信息抓取配置列表
        /// </summary>
        public List<SpiderHotelInfoConfig> HotelInfo
        {
            get;
            set;
        }
        /// <summary>
        /// 酒店房型抓取配置列表
        /// </summary>
        public List<SpiderHotelRoomConfig> HotelRoom
        {
            get;
            set;
        }
        /// <summary>
        /// 酒店评论抓取配置列表
        /// </summary>
        public List<SpiderHotelCommentConfig> HotelComment
        {
            get;
            set;
        }

        /// <summary>
        /// 根据SourceId返回酒店信息抓取配置
        /// </summary>
        /// <param name="SourceId"></param>
        /// <returns></returns>
        public SpiderHotelInfoConfig GetHotelInfoConfig(string SourceId)
        {
            if (HotelInfo == null)
                return null;

            foreach (SpiderHotelInfoConfig shcc in HotelInfo)
            {
                if (shcc.SourceId.ToLower() == SourceId.ToLower())
                    return shcc;
            }
            return null;
        }

        /// <summary>
        /// 根据SourceId返回酒店信息抓取配置
        /// </summary>
        /// <param name="SourceId"></param>
        /// <returns></returns>
        public SpiderHotelRoomConfig GetHotelRoomConfig(string SourceId)
        {
            if (HotelRoom == null)
                return null;

            foreach (SpiderHotelRoomConfig shcc in HotelRoom)
            {
                if (shcc.SourceId.ToLower() == SourceId.ToLower())
                    return shcc;
            }
            return null;
        }

        /// <summary>
        /// 根据SourceId返回点评抓取配置
        /// </summary>
        /// <param name="SourceId"></param>
        /// <returns></returns>
        public SpiderHotelCommentConfig GetSpiderCommentConfig(string SourceId)
        {
            if (HotelComment == null)
                return null;

            foreach (SpiderHotelCommentConfig shcc in HotelComment)
            {
                if (shcc.SourceId.ToLower() == SourceId.ToLower())
                    return shcc;
            }
            return null;
        }

    }

    /// <summary>
    /// 酒店信息抓取配置
    /// </summary>
    public class SpiderHotelInfoConfig
    {
        public string SourceId
        {
            get;
            set;
        }
        public string SpiderUrl
        {
            get;
            set;
        }        
        public string IsValidRegx
        {
            get;
            set;
        }        
        public string HotelNameRegx
        {
            get;
            set;
        }
        public string HotelPicRegx
        {
            get;
            set;
        }        
        public string SnowntownNameRegx
        {
            get;
            set;
        }
        public string HotelStarRegx
        {
            get;
            set;
        }
        public string HotelAddressRegx
        {
            get;
            set;
        }
        public string HotelIntroRegx
        {
            get;
            set;
        }
        public string HotelLngRegx
        {
            get;
            set;
        }
        public string HotelLatRegx
        {
            get;
            set;
        }
        public string HotelTrafficRegx
        {
            get;
            set;
        }
        public string ServicesRegx
        {
            get;
            set;
        }
        public string FacilitiesRegx
        {
            get;
            set;
        }
        public string FoodRegx
        {
            get;
            set;
        }
        public string EntertainmentRegx
        {
            get;
            set;
        }
        public string MeetingRegx
        {
            get;
            set;
        }
        public string PromotionRegx
        {
            get;
            set;
        }

    }
    /// <summary>
    /// 酒店房型抓取配置
    /// </summary>
    public class SpiderHotelRoomConfig
    {
        public string SourceId
        {
            get;
            set;
        }
        public string SpiderUrl
        {
            get;
            set;
        }
        public string IsValidRegx
        {
            get;
            set;
        }
        public string RoomIdRegx
        {
            get;
            set;
        }
        public string RoomNameRegx
        {
            get;
            set;
        }
        public string RoomPriceRegx
        {
            get;
            set;
        }
        public string RoomDescRegx
        {
            get;
            set;
        }
        public string RoomPrizeRegx
        {
            get;
            set;
        }
        public string RoomPromotionRegx
        {
            get;
            set;
        }
    }
    /// <summary>
    /// 酒店点评抓取配置
    /// </summary>
    public class SpiderHotelCommentConfig
    {
        #region 属性
        /// <summary>
        /// 来源ID,如elong,17u等
        /// </summary>
        public string SourceId
        {
            get;
            set;
        }
        /// <summary>
        /// 点评抓取连接地址，带2个参数，酒店ID,分页
        /// </summary>
        public string SpiderUrl
        {
            get;
            set;
        }
        /// <summary>
        /// 编码
        /// </summary>
        public string Encoding
        {
            get;
            set;
        }
        /// <summary>
        /// 酒店点评列表抓取增泽表达式
        /// </summary>
        public string CommentListRegx
        {
            get;
            set;
        }
        /// <summary>
        /// 好评、差评、中评正则表达式
        /// </summary>
        public string IsGoodRegx
        {
            get;
            set;
        }
        public string IsBadRegx
        {
            get;
            set;
        }
        /// <summary>
        /// 发表评论客人ID正则表达式
        /// </summary>
        public string AuthorRegx
        {
            get;
            set;
        }
        /// <summary>
        /// 评论内容正则表达式
        /// </summary>
        public string CommentTextRegx
        {
            get;
            set;
        }
        /// <summary>
        /// 评论日期正则表达式
        /// </summary>
        public string CommentDateRegx
        {
            get;
            set;
        }
        /// <summary>
        /// 卫生服务正则表达式
        /// </summary>
        public string ServiceScoreRegx
        {
            get;
            set;
        }
        /// <summary>
        /// 位置交通分正则表达式
        /// </summary>
        public string TrafficScoreRegx
        {
            get;
            set;
        }
        /// <summary>
        /// 设施服务正则表达式
        /// </summary>
        public string FacilitiesScoreRegx
        {
            get;
            set;
        }
        /// <summary>
        /// 性价比得分正则表达式
        /// </summary>
        public string PriceScoreRegx
        {
            get;
            set;
        }
        /// <summary>
        /// 点评总页数正则表达式
        /// </summary>
        public string PageCountRegx
        {
            get;
            set;
        }
        /// <summary>
        /// 点评起始页码        
        /// </summary>
        public int PageNo
        {
            get;
            set;
        }
        #endregion        
    }
    /// <summary>
    /// 正则表达式配置类
    /// </summary>
    public class RegxConfig
    {
        /// <summary>
        /// 配置文件格式: S|1
        /// </summary>
        /// <param name="config"></param>
        public RegxConfig(string config)
        {
            if (string.IsNullOrEmpty(config))
            {
                this.RegxOption = "S";
                this.Position = 1;
            }
            else
            {
                string[] arr = config.Split('|');
                if (arr.Length == 2)
                {
                    this.RegxOption = arr[0].ToLower();
                    try
                    {
                        this.Position = int.Parse(arr[1]);
                    }
                    catch { }
                }
            }
        }
        /// <summary>
        /// 正则表达式选项 M|N
        /// </summary>
        public string RegxOption
        {
            get;
            set;
        }
        /// <summary>
        /// 解析值位置
        /// </summary>
        public int Position
        {
            get;
            set;
        }
    }
}
